// project imports
import config from '@/config'

// action - state management
import * as actionTypes from './actions'

export interface Customization {
  navType?: string
  isOpen: never[]
  defaultId: string
  fontFamily: string
  borderRadius: number
  opened: boolean
}

export const initialState: Customization = {
  isOpen: [], // for active default menu
  defaultId: 'default',
  fontFamily: config.fontFamily,
  borderRadius: config.borderRadius,
  opened: true
}

// ==============================|| CUSTOMIZATION REDUCER ||============================== //

interface Action {
  type: string
  id: string
  isOpen: never[]
  fontFamily: string
  borderRadius: number
  opened: boolean
}

const customizationReducer = (state = initialState, action: Action) => {
  let id
  switch (action.type) {
    case actionTypes.MENU_OPEN:
      id = action.id
      return {
        ...state,
        isOpen: [id]
      }
    case actionTypes.SET_MENU:
      return {
        ...state,
        opened: action.opened
      }
    case actionTypes.SET_FONT_FAMILY:
      return {
        ...state,
        fontFamily: action.fontFamily
      }
    case actionTypes.SET_BORDER_RADIUS:
      return {
        ...state,
        borderRadius: action.borderRadius
      }
    default:
      return state
  }
}

export default customizationReducer
